import type { Ref } from "vue";
import type { DeptTypeOptionResult } from "@/api/types";
import { ref } from "vue";
import { deptTypeApi } from "@/api";
import { apiCall } from "@/utils/http/apiCall";

interface UseDeptTypeOptions {
    /** 可选择的部门类型列表 */
    deptTypeOptions: Ref<DeptTypeOptionResult[]>;
}

export function useDeptTypeOptions(level: number): UseDeptTypeOptions {
    /** 部门类型列表 */
    const deptTypeOptions = ref<DeptTypeOptionResult[]>([]);

    /** 加载部门类型, 立即执行 */
    (async function loadDeptTypes() {
        await apiCall(
            () => deptTypeApi.listOptions(level),
            (data) => { deptTypeOptions.value = data; },
        );
    })();

    return {
        deptTypeOptions,
    };
}
